package com.imooc.sell.dataobject.mapper;

import com.imooc.sell.dataobject.ProductCategory;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * @author heizi
 * @date 2018/11/8 14:50
 */
public interface ProductCategoryMapper {

    @Insert("insert into product_category(category_name, category_type) value(#{category_name, jdbcType=VARCHAR}, #{category_type, jdbcType=VARCHAR})")
    int insertMap(Map<String, Object> map);

    @Insert("insert into product_category(category_name, category_type) value(#{categoryName, jdbcType=VARCHAR}, #{categoryType, jdbcType=VARCHAR})")
    int insertObject(ProductCategory productCategory);

    @Select("select * from product_category where category_type = #{categoryType}")
    @Results({
            @Result(column = "category_id", property = "categoryId"),
            @Result(column = "category_name", property = "categoryName"),
            @Result(column = "category_type", property = "categoryType")
    })
    ProductCategory findByCategoryType(Integer categoryType);

    @Select("select * from product_category where category_name = #{categoryName}")
    @Results({
            @Result(column = "category_id", property = "categoryId"),
            @Result(column = "category_name", property = "categoryName"),
            @Result(column = "category_type", property = "categoryType")
    })
    List<ProductCategory> findByCategoryName(String categoryName);

    @Update("")
    int updataByCategoryType(@Param("categoryName") String categoryName,
                             @Param("categoryType") int categoryType);

    @Update("")
    int updataByCategoryObject(ProductCategory productCategory);

    ProductCategory selectByCategoryType(Integer categoryType);
}
